package logic

import (
	"context"
	"shopping/model/redis"
	"strconv"

	"shopping/shoprpc/internal/svc"
	"shopping/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeListLogic {
	return &LikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikeListLogic) LikeList(in *shoprpc.LikeListRequest) (*shoprpc.LikeListResponse, error) {
	// todo: add your logic here and delete this line
	itoa := strconv.Itoa(int(in.UserId))

	scores := redis.Rdb.ZRevRangeWithScores("likelist"+itoa, 0, 9)

	var like []*shoprpc.LikeList
	for _, i2 := range scores.Val() {
		list := shoprpc.LikeList{
			Name: i2.Member.(string),
			Like: int64(i2.Score),
		}
		like = append(like, &list)
	}
	return &shoprpc.LikeListResponse{Like: like}, nil
}
